import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/json/base/json_convert_content.dart';

class BaseEntity extends EntityBase {
  //格式化列表实体类
  @override
  T generateListFormJson<T>(List<dynamic> mapList) {
    if (T.toString() == 'List<Map<String, dynamic>>') {
      return mapList.cast<Map<String, dynamic>>() as T;
    } else {
      T t = super.generateListFormJson<T>(mapList);
      if (t == null) {
        t = JsonConvert.fromJsonAsT<T>(mapList);
      }
      return t;
    }
  }

  //格式化一般实体类
  @override
  T generateFormJson<T>(data) {
    if (T.toString() == 'Map<String, dynamic>' ||
        T.toString() == 'double' ||
        T.toString() == 'String' ||
        T.toString() == 'bool') {
      return data as T;
    }
    return JsonConvert.fromJsonAsT<T>(data);
  }
}
